package Carddemo;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

class Card{
    public int rank;
    public String suit;
    public Card(int rank,String suit){
        this.rank = rank;
        this.suit = suit;
    }

    public String toString(){
        return ""+suit+" "+rank;
    }
}
public class Carddemo {

    public static final String[] suits = {"♥","♣","♦","♠"};

    public List<Card> BuyDeskCard(){
        List<Card> cards = new ArrayList<>();
        for (int i = 1; i <= 13; i++) {
            for (int j = 0; j < 4; j++) {
                Card card = new Card(i,suits[j]);
                cards.add(card);
            }
        }
        return cards;
    }


    public void shuffle(List<Card> cards){
        for (int i = cards.size()-1; i >0 ; i--) {
            Random random = new Random();
            int index = random.nextInt(i);
            swap(cards,index,i);
        }
    }
    public void swap(List<Card> cards,int i,int j){
        Card tmp = cards.get(i);
        cards.set(i,cards.get(j));
        cards.set(j,tmp);
    }

    public List<List<Card>> test(List<Card> cards){

        List<Card> player1 = new ArrayList<>();
        List<Card> player2 = new ArrayList<>();
        List<Card> player3 = new ArrayList<>();

        List<List<Card>> players = new ArrayList<>();
        players.add(player1);
        players.add(player2);
        players.add(player3);

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                Card card = cards.remove(0);
                players.get(j).add(card);
            }
        }
        return players;
    }
}
